package edu.lingnan.blog.blog.controller;

import edu.lingnan.blog.api.model.LoginUser;
import edu.lingnan.blog.common.core.domain.pojo.Blog;
import edu.lingnan.blog.blog.service.BlogService;
import edu.lingnan.blog.common.core.web.domain.AjaxResult;
import edu.lingnan.blog.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author cql
 */
@RestController
@RequestMapping("/blog")
public class BlogController {


    @Autowired
    private BlogService blogService;

    @PostMapping
    public AjaxResult insertBlog(@RequestBody Blog blog) {
        /**
         * 参数校验
         */
        LoginUser loginUser = SecurityUtils.getLoginUser();
        blog.setUserId(loginUser.getUserid());
        blogService.saveOrUpdate(blog);
        return AjaxResult.success();
    }
}
